/*     */ package com.yc.dao.query;
/*     */ 
/*     */ import btsm.bean.dbConnector;
/*     */ import com.yc.util.ListContentsBFO;
/*     */ import java.sql.ResultSet;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.logging.Log;
/*     */ import org.apache.commons.logging.LogFactory;
/*     */ 
/*     */ public class QueryDAO
/*     */ {
/*  22 */   private static final Log log = LogFactory.getLog(QueryDAO.class);
/*     */ 
/*  24 */   private dbConnector dbcon = null;
/*  25 */   private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/*     */ 
/*  27 */   private static Map countMap = new HashMap();
/*     */ 
/*     */   private void dbConInit() {
/*  30 */     if (this.dbcon == null)
/*  31 */       this.dbcon = new dbConnector();
/*     */   }
/*     */ 
/*     */   public void dbConClose() {
/*  35 */     if (this.dbcon != null)
/*  36 */       this.dbcon.closeAll();
/*  37 */     this.dbcon = null;
/*     */   }
/*     */ 
/*     */   public ListContentsBFO query(Map condition) {
/*  41 */     dbConInit();
/*  42 */     ListContentsBFO bfo = new ListContentsBFO();
/*  43 */     Object queryTable = condition.get("QUERY_TABLE");
/*  44 */     if (queryTable == null) {
/*  45 */       bfo.setTotalSize(0);
/*  46 */       bfo.setData(new ArrayList().toArray());
/*  47 */       return bfo;
/*     */     }
/*  49 */     List tableList = (List)queryTable;
/*  50 */     String strBtsName = condition.get("btsName").toString();
/*     */ 
/*  52 */     List returnList = new ArrayList();
/*  53 */     int totalSize = tableList.size();
/*  54 */     ResultSet rs = null;
/*     */     try
/*     */     {
/*  57 */       Object objRegistBeginTime = condition.get("registBeginTime");
/*  58 */       Object objRegistEndTime = condition.get("registEndTime");
/*  59 */       if ((objRegistBeginTime == null) || ("".equalsIgnoreCase(objRegistBeginTime.toString().trim())))
/*  60 */         objRegistBeginTime = null;
/*  61 */       if ((objRegistEndTime == null) || ("".equalsIgnoreCase(objRegistEndTime.toString().trim()))) {
/*  62 */         objRegistEndTime = null;
/*     */       }
/*     */ 
/*  68 */       dbConInit();
/*     */ 
/*  70 */       for (int i = 0; i < totalSize; i++)
/*     */       {
/*  72 */         QueryBO bo = (QueryBO)tableList.get(i);
/*     */         String strSQL;
/*  73 */         if ("geographicalenv".equalsIgnoreCase(bo.getTableName())) {
/*  74 */           strSQL = " select count(btscode) from " + bo.getTableName() + " where btsname like '%" + strBtsName + "%' ";
/*     */         }
/*     */         else
/*     */         {
/*  75 */           if (("mainssupply".equalsIgnoreCase(bo.getTableName())) || 
/*  76 */             ("machineroom".equalsIgnoreCase(bo.getTableName())) || 
/*  77 */             ("antennafeeder".equalsIgnoreCase(bo.getTableName())) || 
/*  78 */             ("powersupply".equalsIgnoreCase(bo.getTableName())) || 
/*  79 */             ("transfers".equalsIgnoreCase(bo.getTableName())) || 
/*  80 */             ("irontower".equalsIgnoreCase(bo.getTableName())) || 
/*  81 */             ("trafficinfo".equalsIgnoreCase(bo.getTableName())))
/*     */           {
/*  83 */             strSQL = " select count(id) from " + bo.getTableName() + " where btsname like '%" + strBtsName + "%'";
/*     */           }
/*     */           else
/*     */           {
/*  84 */             if ("acdcdistribution".equalsIgnoreCase(bo.getTableName()))
/*     */             {
/*  86 */               strSQL = " select count(id) from " + bo.getTableName() + " where btsname like '%" + strBtsName + "%' or distmanufacturer like '%" + strBtsName + "%'";
/*     */             }
/*  88 */             else strSQL = " select count(id) from " + bo.getTableName() + " where btsname like '%" + strBtsName + "%' or manufacturer like '%" + strBtsName + "%'"; 
/*     */           }
/*     */         }
/*  89 */         if ((objRegistBeginTime != null) && (objRegistEndTime != null))
/*  90 */           strSQL = strSQL + " and '" + objRegistEndTime.toString() + "'>= registtime and  registtime >= '" + objRegistBeginTime.toString() + "' ";
/*  91 */         else if ((objRegistBeginTime == null) && (objRegistEndTime != null))
/*  92 */           strSQL = strSQL + " and '" + objRegistEndTime.toString() + "' >= registtime ";
/*  93 */         else if ((objRegistBeginTime != null) && (objRegistEndTime == null)) {
/*  94 */           strSQL = strSQL + " and registtime >= '" + objRegistBeginTime.toString() + "'  ";
/*     */         }
/*     */ 
/*  97 */         log.info(strSQL);
/*  98 */         rs = this.dbcon.execQuery(strSQL);
/*  99 */         if (rs.next())
/*     */         {
/* 101 */           if (rs.getInt(1) > 0)
/*     */           {
/* 103 */             bo.setNum(String.valueOf(rs.getInt(1)));
/* 104 */             returnList.add(bo);
/*     */           }
/*     */ 
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 114 */       e.printStackTrace();
/*     */     }
/*     */     finally {
/* 117 */       dbConClose();
/*     */     }
/* 119 */     bfo.setTotalSize(totalSize);
/* 120 */     bfo.setData(returnList.toArray());
/* 121 */     return bfo;
/*     */   }
/*     */ }

/* Location:           E:\java\apache-tomcat-6.0.36\webapps\btsm\WEB-INF\classes\
 * Qualified Name:     com.yc.dao.query.QueryDAO
 * JD-Core Version:    0.6.2
 */